<!DOCTYPE html>
<html>
  <head>
    <title><%= title %></title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
  </head>
  <body>
    <input type="text" id="username">
    <input type="password" id="password">
    <button id="login">登录</button>
  </body>
  <script>
    let userName = document.querySelector('#username');
    let passWord = document.querySelector('#password');

    let loginbtn = document.querySelector('#login')

    loginbtn.onclick = function () {
      let username = userName.value;
      let password = passWord.value;

      fetch('http://localhost:3000/login',{
        method:'POST',
        body:JSON.stringify({username,password})
      })
      .then(res => res.json())
      .then(res => {
        console.log(res)
        if(res.token) {
          localStorage['token'] = res.token
        }
      }
        
      )
    }
  </script>
</html>
